package com.ruoyi.web.controller.used;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.used.domain.UsedGoodsDetails;
import com.ruoyi.used.service.IUsedGoodsDetailsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品详情Controller
 * 
 * @author ruoyi
 * @date 2020-07-11
 */
@Controller
@RequestMapping("/used/details")
public class UsedGoodsDetailsController extends BaseController
{
    private String prefix = "used/details";

    @Autowired
    private IUsedGoodsDetailsService usedGoodsDetailsService;

    @RequiresPermissions("used:details:view")
    @GetMapping()
    public String details()
    {
        return prefix + "/details";
    }

    /**
     * 查询商品详情列表
     */
    @RequiresPermissions("used:details:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UsedGoodsDetails usedGoodsDetails)
    {
        startPage();
        List<UsedGoodsDetails> list = usedGoodsDetailsService.selectUsedGoodsDetailsList(usedGoodsDetails);
        return getDataTable(list);
    }

    /**
     * 导出商品详情列表
     */
    @RequiresPermissions("used:details:export")
    @Log(title = "商品详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UsedGoodsDetails usedGoodsDetails)
    {
        List<UsedGoodsDetails> list = usedGoodsDetailsService.selectUsedGoodsDetailsList(usedGoodsDetails);
        ExcelUtil<UsedGoodsDetails> util = new ExcelUtil<UsedGoodsDetails>(UsedGoodsDetails.class);
        return util.exportExcel(list, "details");
    }

    /**
     * 新增商品详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品详情
     */
    @RequiresPermissions("used:details:add")
    @Log(title = "商品详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UsedGoodsDetails usedGoodsDetails)
    {
        return toAjax(usedGoodsDetailsService.insertUsedGoodsDetails(usedGoodsDetails));
    }

    /**
     * 修改商品详情
     */
    @GetMapping("/edit/{deId}")
    public String edit(@PathVariable("deId") Long deId, ModelMap mmap)
    {
        UsedGoodsDetails usedGoodsDetails = usedGoodsDetailsService.selectUsedGoodsDetailsById(deId);
        mmap.put("usedGoodsDetails", usedGoodsDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品详情
     */
    @RequiresPermissions("used:details:edit")
    @Log(title = "商品详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UsedGoodsDetails usedGoodsDetails)
    {
        return toAjax(usedGoodsDetailsService.updateUsedGoodsDetails(usedGoodsDetails));
    }

    /**
     * 删除商品详情
     */
    @RequiresPermissions("used:details:remove")
    @Log(title = "商品详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(usedGoodsDetailsService.deleteUsedGoodsDetailsByIds(ids));
    }
}
